<?php
/*
 * @Author: your name
 * @Date: 2020-10-14 09:56:42
 * @LastEditTime: 2020-12-28 14:08:58
 * @LastEditors: Please set LastEditors
 * @Description: 防火墙通信规则(保证客户端与平台和中间通信键的正常通信)
 * @FilePath: /special/application/adminapiv3/controller/module_manage/netfilter/FirewallSafeRuleController.php
 */

namespace app\adminapiv3\controller\module_manage\netfilter;

use app\adminapiv3\service\module_manage\netfilter\FirewallSafeRuleService;
use think\Request;

class FirewallSafeRuleController extends NetfilterBaseController
{

    /**
     * @name: 通信规则列表
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-20 16:11:22
     */
    public function safeRuleList (Request $request)
    {
        $input = $request->only(['host_id'], 'post');
        $this->validate($input, 'FirewallSafeRule.list');

        $FirewallSafeRuleService = new FirewallSafeRuleService();
        $data = $FirewallSafeRuleService->safeRuleList($input['host_id']);
        
        return $this->jsonOutPut($data);
    }

    /**
     * @name: 通信规则开启
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-20 16:12:06
     */
    public function safeRuleOn (Request $request)
    {
        $input = $request->only(['host_id','rule_id'], 'post');
        $this->validate($input, 'FirewallSafeRule.offOn');

        $FirewallSafeRuleService = new FirewallSafeRuleService();
        $data = $FirewallSafeRuleService->safeRuleOn($input['host_id'], $input['rule_id']);

        //下发命令 查询规则列表
        $this->sendCommandToClient('netfilter','downloadRules');
        return $this->jsonOutPut($data, true);
    }

    /**
     * @name: 通信规则关闭
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-20 16:12:06
     */
    public function safeRuleOff (Request $request)
    {
        $input = $request->only(['host_id','rule_id'], 'post');
        $this->validate($input, 'FirewallSafeRule.offOn');

        $FirewallSafeRuleService = new FirewallSafeRuleService();
        $data = $FirewallSafeRuleService->safeRuleOff($input['host_id'], $input['rule_id']);

        //下发命令 查询规则列表
        $this->sendCommandToClient('netfilter','downloadRules');
        return $this->jsonOutPut($data, true);
    }
}